<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-perTemplateSpecRelation-edit" >
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <h5><span class="text-danger">请重新根据模板内容制定考核信息，单项考核项权重不建议超过60%,权重之和必须等于100</span></h5>
                    </div>
                    <div class="ibox-content" >
                        <input type="hidden" id="size" th:value="${relations.size()}"/>
                        <div class="row" th:each="relation,status:${relations}">
                            <div class="col-sm-12">
                                <div  th:class="${relation.weight>=60?'panel panel-danger':'panel panel-default'}">
                                    <div class="panel-heading" >
                                        <div class="row" >
                                            <div class="col-md-6" >
                                                <label  class="control-label" th:text="${relation.specName}"></label>
                                            </div>
                                            <div class="col-md-2" style="text-align: right"><label  class="control-label">权重(%):</label> </div>
                                            <div class="col-md-2">
                                                    <input type="text"  class="form-control input-sm" th:attr="relationId=${relation.relationId}" th:id="'weight'+${status.index}" name="weight" th:value="${relation.weight}">
                                                    <input type="hidden" th:id="'specId'+${status.index}" th:value="${relation.specId}">
                                            </div>

                                        </div>
                                           <!-- <label class="col-sm-3 control-label" th:text="${relation.specName}"></label>
                                            <label class="col-sm-3 control-label">权重(%)：</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" th:attr="relationId=${relation.relationId}" th:id="'weight'+${status.index}" name="weight" th:value="${relation.weight}">
                                            </div>-->
                                    </div>

                                    <div class="panel-body" >

                                        <textarea class="form-control" th:id="'specContent'+${status.index}" rows="6" th:text="${relation.specContent}"></textarea>
                                    </div>

                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>

    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "performance/perTemplateSpecRelation";
    $("#form-perTemplateSpecRelation-edit").validate({
        rules:{
            xxxx:{
                required:true,
            },

        },
        focusCleanup: true
    });
    change();
    function submitHandler() {
        if ($.validate.form()) {
            var sumWeight=0;
            var data=[];
            flag=true;
            $('input[name=weight]').each(function(a,b){
                var re = /^[0-9]+.?[0-9]*$/
                if (!re.test($(b).val())){
                    flag=false;
                    return;
                }
                sumWeight+=parseInt($(b).val())
                var relation={'relationId':$(b).attr('relationId'),'weight':$(b).val()}
                data.push(relation);
            });
            if(!flag){
                $.modal.alertWarning('权重必须为1-99的数字');
                return;
            }
            if(sumWeight!=100){
                $.modal.alertWarning('权重只和必须等于100');
                return;
            }
            var size=$('#size').val();
            var data=[];
            for(var i=0;i<size;i++){
                var adata={};
                adata['specId']=$('#specId'+i).val();
                adata['actualWeight']=$('#weight'+i).val();
                adata['actualSpecContent']=$('#specContent'+i).val();
                data.push(adata);
            }
            console.info(data);
            return data;
            //$.operate.save(ctx + "performance/perTemplateSpecRelation/updateWeight", {'relations':JSON.stringify(data)});
        }
    }
    function change(){
        $('#specContent').text($('#spec option:selected').attr("specContent"));
        $('#specId').val($('#spec option:selected').val())
    }

</script>
</body>
</html>
